<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\AgentWalletLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Support\Facades\DB;

class AgentWalletLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AgentWalletLog(), function (Grid $grid) {

            $grid->disableCreateButton();

            //切换操作列显示样式
            // $grid->setActionClass(Grid\Displayers\Actions::class);

            //禁用操作列
            $grid->disableActions();

            $grid->number('序号');
            $grid->column('user_name');
            $grid->column('agent');
            $grid->column('user_id', __('门店'))->display(function ($user_id) {
                return DB::table('users')->where('id',$user_id)->value('name');
            });
            $grid->column('order_id');
            $grid->column('order_total_money');
            $grid->column('agent_proportion');
            $grid->column('commission');
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new AgentWalletLog(), function (Show $show) {
            $show->field('id');
            $show->field('user_name');
            $show->field('agent');
            $show->field('user_id');
            $show->field('order_id');
            $show->field('order_total_money');
            $show->field('agent_proportion');
            $show->field('commission');
            $show->field('created_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AgentWalletLog(), function (Form $form) {
            $form->display('id');
            $form->text('user_name');
            $form->text('agent');
            $form->text('user_id');
            $form->text('order_id');
            $form->text('order_total_money');
            $form->text('agent_proportion');
            $form->text('commission');
            $form->text('created_at');
        });
    }
}
